
#ifndef _COMMON_
#define _COMMON_



#if defined(DEBUG_IN_PC)
typedef char            int8_t;
typedef unsigned char   uint8_t;
typedef short           int16_t;
typedef unsigned short  uint16_t;
typedef int             int32_t;
typedef unsigned int    uint32_t;


#define UC  L
#else
#include <stdint.h>

#define UC
#endif


#include "GUI.h"



//extern  GUI_FONT  GUI_FontFont24;
//extern  GUI_FONT  GUI_FontFont32;
//extern  GUI_FONT  GUI_FontFont48;
//extern  GUI_FONT  GUI_FontFontNumber64;
//
//
//#define GUI_FONT_16
//#define GUI_FONT_24  GUI_FontFont24
//#define GUI_FONT_32  GUI_FontFont32
//#define GUI_FONT_48  GUI_FontFont48
//#define GUI_FONT_64  GUI_FontFontNumber64





/* Widget type                                               */
#define WIDGET_NULL            0
#define WIDGET_WINDOW          1
#define WIDGET_BUTTON          2
#define WIDGET_STATIC_TEXT     3
#define WIDGET_SLIDE           4
#define WIDGET_PROGBAR         5
#define WIDGET_LIST_WHEEL      6
#define WIDGET_BUTTON_SLIDE    7
#define WIDGET_EDIT            8
#define WIDGET_DROPDOWN        9
#define WIDGET_CHECKBOX       10
#define WIDGET_EDIT           11



#define WIDGET_NUMBER         10


#define EDIT_MODE_DISABLED     0
#define EDIT_MODE_ENABLED      1

#define GUI_STATE_INVALID      0
#define GUI_STATE_VALID        1




#if defined(__cplusplus)
extern "C" {     /* Make sure we have C-declarations in C++ programs */
#endif


typedef struct {
	void *pNext;

	uint16_t address;                            // group address
	uint16_t dataPointType;                      // data type
	uint32_t beforeDelay;                        // Delay "beforeDelay" milliseconds before sending command
} GroupAddressMsg, *pGroupAddressMsg;


typedef struct {
	GUI_HMEM        hMem;
	GUI_BITMAP      bitMap;
	GUI_LOGPALETTE  palette;
} BitMap, *pBitMap;


typedef union {
	uint32_t occupy[3];

	struct {
		uint8_t  inPassword1;                 // 内部保存的密码
		uint8_t  inPassword2;
		uint8_t  inPassword3;
		uint8_t  inPassword4;

		GUI_HMEM cipherTimer;

		uint16_t cipherPreperiod : 12;
		uint16_t cipherOK : 1;
		uint16_t cipherModify : 1;
		uint16_t rsv : 2;
	} encryption;

	struct {
		uint16_t rangeStart;
		uint16_t rangeEnd;
		uint16_t thumbWidth;
		uint8_t  useFlag;
	} slider;
} SpecialInfo, *pSpecialInfo;


typedef struct {
	void      *pPreviousLayer;                   // 上级窗口句柄，当前支持最多两级窗口嵌套
	void      *pNextLayer;                       // 下级窗口句柄

	void      *pParallelNext;                    // 同层，下一个窗口句柄
	void      *pTimeNext;                        // 仅用于时间功能
    int32_t   parent;                            // 父窗口句柄
	uint8_t   winLayer;                          // 窗口层级，当前支持1和2两层。                        
	uint8_t   transparency;                      // 主窗口是否透明
	uint8_t   slideFlag;                         // 指示滑动方向
	uint8_t   guiState;                          // 指示窗口/控件是否有效, 0：表示正在冷启动，1：表示控件已创建，2：表示控件没创建或已被删除

	struct {
		uint16_t  id;                            // widget ID
		uint8_t   winType;                       // window type
		uint8_t   showWindow;                    // show flag
		uint8_t   winName[100];                  // window name
		uint16_t  xPos;                          // X axis
		uint16_t  yPos;                          // Y axis
		uint16_t  xSize;                         // X size
		uint16_t  ySize;                         // Y size
		uint16_t  isMoving;
		uint16_t  align;                         // 对齐方式
		GUI_FONT  *pFont;
		void      (*pRedraw)(void*);

		SpecialInfo specialInfo;
		uint8_t     onPath[50];
		uint8_t     offPath[50];
        uint8_t     backPath[50];
		BitMap      pictureOn;
		BitMap      pictureOff;
        BitMap      pictureBack;
		GUI_BITMAP  *pCurrentPicture;
//        GUI_MEMDEV_Handle hCurrentPicture;
	} guiTCB;

	struct {
		uint8_t          keyMsg;
		uint8_t          guiState;
		uint16_t         funType;
		uint32_t         textNumber;
		pGroupAddressMsg addrList;
	} appTCB;
} PARA_TCB, *pPARA_TCB;









extern  GUI_FONT  GUI_FontFont24;
extern  GUI_FONT  GUI_FontFont32;
extern  GUI_FONT  GUI_FontFont48;
extern  GUI_FONT  GUI_FontFont64;


#define GUI_FONT_16
#define GUI_FONT_24  GUI_FontFont24
#define GUI_FONT_32  GUI_FontFont32
#define GUI_FONT_48  GUI_FontFont48
#define GUI_FONT_64  GUI_FontFont64






int16_t GetUniqueID(void);
uint8_t *GetWidetTypeName(uint16_t winType);
uint16_t GetWidgetNumber(pPARA_TCB pParaTcb);
void SetEditMode(uint8_t mode);
uint8_t GetEditMode(void);
void SetWidgetText(pPARA_TCB pParaTcb, uint8_t *pStr);
void AddStringToBuffer(uint8_t *pOutArray, uint8_t *pSrcString);



#if defined(__cplusplus)
}
#endif

#endif // !_COMMON_
